home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr23 / chansw53.zip / CHAIN5.CPP < prev    next >
C/C++ Source or Header  |  1993-05-24  |  3KB  |  129 lines

  1.  
  2. // FILE: CHAIN5.CPP
  3. // MODULE: PASSWORD
  4. // PROGRAM: CHAINSAW 
  5.  
  6. // Public Domain, 5/24/93, 1993, Ted Davis
  7.  
  8. #include "chainsaw.hpp"
  9.  
  10.  
  11. int ChangePassword(char * new_password, char *argv0, char * Switches)
  12. // This is intentionally uncommented.
  13. {
  14. int handle, rcode = no;
  15. char Key[password_len], Pword[password_len], Marker[Marker_len];
  16.  
  17.     new_password[15] = '\0';
  18.     strcpy(Pword, new_password);
  19.     if((handle = _open(argv0, O_RDWR)) != -1)
  20.     {
  21.         if((lseek(handle, KeyOffset, SEEK_SET)) != -1)
  22.         {
  23.             if((read(handle, Key, password_len)) == password_len)
  24.             {
  25.                 if((lseek(handle, ID_Offset, SEEK_END)) != -1)
  26.                 {
  27.                     if((read(handle, Marker, Marker_len)) == Marker_len)
  28.                     {
  29.                         Encrypt(Key, Marker, Marker_len);
  30.                         if(!strncmp(Marker, MarkerText, Marker_len))
  31.                         {
  32.                             if((lseek(handle, PwordOffset, SEEK_END)) != -1)
  33.                             {
  34.                                 Encrypt(Key, new_password, password_len);
  35.                                 if(((write(handle, new_password,\
  36.                                 password_len)) != -1) && ((write(handle,\
  37.                                 Switches, switches_len)) != -1))
  38.                                 {
  39.                                     rcode = yes;
  40.                                 }
  41.                             }
  42.                         }
  43.                         else
  44.                         {
  45.                             if((lseek(handle, 0, SEEK_END)) != -1)
  46.                             {
  47.                                 strncpy(Marker, MarkerText,16);
  48.                                 Encrypt(Key, Marker, Marker_len);
  49.                                 Encrypt(Key, Pword, password_len);
  50.                                 if(((write(handle, Marker, Marker_len))\
  51.                                 != -1) && ((write(handle, Pword, password_len))\
  52.                                 != -1) && ((write(handle,\
  53.                                 Switches, switches_len)) != -1)) 
  54.                                 {
  55.                                     rcode = yes;
  56.                                 }
  57.                             }
  58.                         }
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.         if((_close(handle)) == -1)
  64.         {
  65.             rcode = no;
  66.         }
  67.     }
  68.     return(rcode);    
  69. }
  70.  
  71.  
  72.  
  73. int UserPassword(char * password, char * argv0, char * Switches, char * Pword)
  74. // This is intentionally uncommented.
  75. {
  76. int handle, rcode = no;
  77. char Key[password_len], Marker[Marker_len];
  78.  
  79.     strncpy(Marker, MarkerText, 16);
  80.     if((handle = _open(argv0, O_RDONLY)) != -1)
  81.     {
  82.         if((lseek(handle, KeyOffset, SEEK_SET)) != -1)
  83.         {
  84.             if((read(handle, Key, password_len)) == password_len)
  85.             {
  86.                 if((lseek(handle, ID_Offset, SEEK_END)) != -1)
  87.                 {
  88.                     if((read(handle, Marker, Marker_len)) == Marker_len)
  89.                     {
  90.                         Encrypt(Key, Marker, Marker_len);
  91.                         if(!strncmp(Marker, MarkerText, Marker_len))
  92.                         {
  93.                             if((lseek(handle, PwordOffset, SEEK_END)) != -1)
  94.                             {
  95.                                 read(handle, Pword, password_len);
  96.                                 read(handle, Switches, switches_len);
  97.                                 // Assuming that read does not fail may not
  98.                                 // be the best of ideas, but it does simplify
  99.                                 // the structure.
  100.                             }
  101.                         }
  102.                         else
  103.                         {
  104.                             strcpy(Pword, PassWord);
  105.                             Encrypt(Key, Pword, password_len);
  106.                             strcpy(Switches, DefaultSwitchString);
  107.                         }
  108.                         Encrypt(Key, Pword, password_len);
  109.                         if(!strcmp(Pword, "")) 
  110.                         {
  111.                             rcode = yes;
  112.                         }
  113.                         else
  114.                         {
  115.                             if(!strcmp(Pword, password)) {rcode = yes;}
  116.                         }
  117.  
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.         if((_close(handle)) == -1)
  123.         {
  124.             rcode = no;
  125.         }
  126.     }
  127.     return(rcode);    
  128. }
  129.